package util

import (
	"github.com/worklz/go-validate"
)

// 数据验证
// Param: v 验证器实例
// Param: datas 数据
// Param: rules 规则
// Param: titles 标题
// Param: scene 场景
// Return: error
func DatasValidate(v validate.ValidatorInterface, datas map[string]any, rules map[string]any, titles map[string]string, scene string) (err error) {
	err = v.SetRules(rules)
	if err != nil {
		return
	}
	err = v.SetTitles(titles)
	if err != nil {
		return
	}
	err = v.SetDatas(datas)
	if err != nil {
		return
	}
	err = v.CheckScene(scene)
	if err == nil {
		datas, err = v.GetDatas()
	}
	return
}
